import { createApp } from 'vue';//创建应用===造花盆
import App from './App.vue';//组件===根
import "@/assets/less/index.less";
import router from './router';
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createPinia } from 'pinia';
import "@/api/mock.js";
import api from "@/api/api";
import {useAllDataStore} from "@/stores"
// import './assets/main.css';
// import '@/assets/less/reset.less';
function isRoute(to){
    let res = router.getRoutes();
    let resFil = res.filter((item) => item.path === to.path)
    return resFil.length > 0
}
router.beforeEach((to,from)=>{
    if(to.path !== '/login' && !store.state.token){
        return {name:"login"};
    }
    if(!isRoute(to)){
        return {name : "404"};
    }
});
const pinia = createPinia();
const app = createApp(App);
//拿到相关接口
app.config.globalProperties.$api = api;
//把花插在花盆里
app.use(pinia);
const store = useAllDataStore();
app.use(ElementPlus);
store.addMenu(router,"refresh");
app.use(router).mount('#app');
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
